RUN a file using Parameters

by Gordon Sweet

Home

Tips For the Hobbyist

Nally's Applications

Measuring an Angle

Maphandle Listboxes

About GUIs

Convert Old Code

Installing Fonts

Tip Corner

Stopwatch for LB4

Run with Params

Newsletter help

Index


I have always thought that one of the greatest shortcomings of Windows, is that there appears to be no simple way of activating a program using parameters. This is obviously why much of the software needs a vast variety of buttons and menus to utilize various options. Some of the earlier simple programs such as those intended to be run under DOS, never had such luxuries, and can only be run using parameters.

It is true many programs involving existing files can to used by the rather crude method of dragging the parameter file onto the main RUN file, or by entering a complex command line using the Run function beneath the Start button. The latter would probably need to include a long string of file paths for the two files involved, unless installed in the default PATH line. Another way is the rather old fashioned method of creating and using a .BAT file.

This little program should solve the problem in many cases. You only need to find the main Run file in the simplest instance, try using Notepad.exe and click ACTIVATE; or use Notepad along with a suitable TXT file as the Parameter file. Remember some programs display the parameters available by just activating the program, or in some cases by using ? for the parameter.

I am sure I do not need to warn of the danger of activating any programs that you are unsure of their purpose. This especially applies to those in any of the Windows directories.

Gordon Sweet

editor's notes: Programs can be run with parameters using ShellExecuteA. See issue #109. See also issue #114 for using the RUN command with parameters. See issue #103 for more on ShellExecuteA.

' Allows any EXE COM or BAT file to be run using Parameters

    nomainwin
    ux = 1 : uy = 1
    if DisplayWidth > 1000 then ux = 120 : uy = 90
    UpperLeftX = ux : UpperLeftY = uy
    WindowWidth = 800 : WindowHeight = 200
    button #s "Main RUN file ", [main], UL, 200, 20
    button #s "Any Parameters", [param], UL, 350, 20
    button #s "Any Param file", [file], UL, 500, 20
    button #s "Activate", [go], UL, 300, 60
    button #s "* QUIT *", [quit], UL, 450, 60
    open "File Activator" for graphics_nsb as #s

[start]
    #s "trapclose [quit]; font fixedsys; place 20 130; down"
    #s "\";space$(30);"Run any SAFE file using Parameters"
    CurrentDir$ = DefaultDir$ 
    Run$ ="" : File$ = "" : Param$ = "" : op$ = ""
    wait

[hold]
    op$ = Run$+Param$+File$
    #s "cls; place 20 130"
    #s "|";op$ 
    wait

[main]
    Type$ = "*.exe;*.com;*.bat"
    DefaultDir$ = left$(DefaultDir$,2) + "\"
    filedialog "Any SAFE exe, com, bat file",Type$,Run$
    if Run$ = "" then [quit]
    Run$=GetShortPathName$(Run$)
    Dir$ = DefaultDir$
    goto [hold]

[file]
    DefaultDir$ = left$(DefaultDir$,2) + "\"
    filedialog "Any Parameter File","*.*",File$
    if File$ = "" then notice "Nothing Selected"
    if File$<>"" then File$=" "+GetShortPathName$(File$)
    goto [hold]

[param]
    prompt "Enter parameters";Param$
    if Param$ = "" then notice "Nothing Selected"
    if Param$<>"" then Param$=" "+Param$
    goto [hold]

[go]
    if op$ = "" then notice "No Main File" : goto [start]
    DefaultDir$ = Dir$
    run op$, restore
    goto [start]

[quit]
    close #s : end

Function GetShortPathName$(lPath$)
    lPath$=lPath$+Chr$(0)
    sPath$=Space$(256)
    lenPath=Len(sPath$)
    CallDLL #kernel32, "GetShortPathNameA",lPath$ As ptr,_
    sPath$ As ptr,lenPath As long,r As long
    GetShortPathName$=Left$(sPath$,r)
    End Function


Home

Tips For the Hobbyist

Nally's Applications

Measuring an Angle

Maphandle Listboxes

About GUIs

Convert Old Code

Installing Fonts

Tip Corner

Stopwatch for LB4

Run with Params

Newsletter help

Index